//
//  MineViewController.m
//  FaceTo
//
//  Created by chijia on 2017/6/18.
//  Copyright © 2017年 chengbangming. All rights reserved.
//

#import "MineViewController.h"
#import "UIBarButtonItem+Extension.h"
#import "AppDelegate.h"
#import "FTProfileHeaderView.h"
#import "MLMSegmentManager.h"
#import "FTRankTableView.h"
#import "FTTodayScoreView.h"
#import "FTChartView.h"
#import "FTProfileInforViewController.h"

@interface MineViewController ()

@property (nonatomic, strong) MLMSegmentHead *segHead;
@property (nonatomic, strong) MLMSegmentScroll *segScroll;

@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = WhiteColor;
    
    [self initNav];
    
    [self initUI];
}

// 初始化navbar
- (void)initNav
{
    // nav左边按钮
    UIBarButtonItem *menubtn = [UIBarButtonItem itemWithImageName:@"menu" highImageName:@"menu" target:self action:@selector(menuClick:)];
    UIBarButtonItem *logoBtn = [UIBarButtonItem itemWithImageName:@"small_md" highImageName:@"small_md" target:self action:nil];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeCustom]];
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:menubtn, item, logoBtn, nil];
    
    // nav右边按钮
    UIBarButtonItem *editBtn = [UIBarButtonItem itemWithImageName:@"edit" highImageName:@"edit" target:self action:@selector(editClick)];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeCustom]];
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:editBtn, item1, nil];
}

// 点击打开侧滑
- (void)menuClick:(UIButton *)sender
{
    CKLeftSlideViewController *leftSlide = (CKLeftSlideViewController *)[((AppDelegate *)[UIApplication sharedApplication].delegate) leftSlideVc];
    [leftSlide openLeftView];
}

// 个人资料编辑
- (void)editClick
{
    FTProfileInforViewController *vc = [[FTProfileInforViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)initUI
{
    FTProfileHeaderView *headerView = [[FTProfileHeaderView alloc] init];
    [self.view addSubview:headerView];
    
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.offset(0);
        make.width.mas_equalTo(kSCREEN_WIDTH);
        make.height.mas_equalTo(170);
    }];
    
    NSArray *list = @[@"今日积分",
                      @"日均积分",
                      @"今日排名"
                      ];
    _segHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(0, 170, SCREEN_WIDTH, 40) titles:list headStyle:1 layoutStyle:0];
    _segHead.fontScale = 1;
    _segHead.fontSize = 14;
    _segHead.lineScale = 1;
    _segHead.lineColor = FTColor;
    _segHead.bottomLineColor = Color(237, 237, 237);
    
    _segScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_segHead.frame), SCREEN_WIDTH, SCREEN_HEIGHT-CGRectGetMaxY(_segHead.frame)) vcOrViews:[self viewNameArr]];
    _segScroll.loadAll = NO;
    _segScroll.showIndex = 0;
    
    [MLMSegmentManager associateHead:_segHead withScroll:_segScroll completion:^{
        [self.view addSubview:_segHead];
        [self.view addSubview:_segScroll];
    }];
}

#pragma mark - 数据源
//- (NSArray *)viewArr:(NSInteger)count
//{
//    NSMutableArray *arr = [NSMutableArray array];
//    for (NSInteger i = 0; i < count; i ++) {
//        FTRankTableView *view = [NSClassFromString(@"FTRankTableView") new];
//        [arr addObject:view];
//    }
//    return arr;
//}

- (NSArray *)viewNameArr
{
    return @[@"FTTodayScoreView",
             @"FTChartView",
             @"FTRankTableView"
             ];
}
@end
